<template>
	<view>
<<<<<<< HEAD

		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="user.username" 
				placeholder="请输入用户名" />
			</uni-forms-item>



			<uni-forms-item label="" name="">
				<uni-easyinput v-model="user.password" type="password" placeholder="请输入密码" />
			</uni-forms-item>
			
			<uni-forms-item label="" name="">
				<button  @click="login" type="primary">登录</button>
			</uni-forms-item>
			
		</uni-forms>
=======
		<view class="img" style="text-align: center; height: 220px;">
			<image src="../../static/images/2.png" mode="" style="
			width: 250px;
			height: 250px;
			scale: 0.4;
			"></image>
		</view>


		<view class="input">

			<uni-forms ref="form" :model="user" :rules="rules">
				<uni-forms-item label="用户名" name="name">
					<uni-easyinput v-model="user.name" placeholder="请输入用户名" />


				</uni-forms-item>

				<uni-forms-item class="psw" label="密码" name="password">
					<uni-easyinput placeholder="请输入密码" type="password" v-model="user.password" />
				</uni-forms-item>

				<uni-forms-item name="">
					<button type="primary" @click="login">登录</button>
				</uni-forms-item>
			</uni-forms>

		</view>

>>>>>>> d747fee (作业13)

	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
<<<<<<< HEAD
					username: 'zcy',
					password: '123'
				}
			}
		},
		methods: {
			
			login(e){
			   console.log(e);
			   uni.showToast({
			   	title:this.user.username + '登录成功'
			   })
			}

=======
					name: '张三',
					password: '123',
				},
				rules: {

					username: {
						rules: [{
							required: true,
							errorMessage: '请输入用户名',
						}]
					},
					password: {
						rules: [{
								required: true,
								errorMessage: '请输入密码',
							},
							{
								minLength: 3,
								maxLength: 5,
								errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符',
							}
						]
					}
				},

			}
		},
		methods: {
			login(e) {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/user/login',
					method: 'post',
					data: this.user,
					success: res => {
						console.log(res);
						if (res.data.success === true) {
							uni.showToast({
								title: res.data.data.name + '登录成功',
								icon: "success"
							});
							uni.setStorageSync('userinfo', res.data.data)
							uni.switchTab({
								url: '../my/my'
							})

						} else {
							uni.showToast({
								title: '用户名或密码错误',
								icon: 'error'
							});
						}
					},
					fail: (err) => {
						uni.showToast({
							title: '网络错误',
							icon: 'error'
						});
					},
					complete: () => {}
				});

			}
>>>>>>> d747fee (作业13)
		}
	}
</script>

<<<<<<< HEAD
<style>

=======
<style scoped>
	.input {
		width: 90%;
		margin: auto !important;
	}
>>>>>>> d747fee (作业13)
</style>